<%-- 
    Document   : book-list
    Created on : 24.4.2011, 20:45:47
    Author     : MantaEx
--%>

<%@page import="jlibrarian.entities.Book"%>
<%@page import="jlibrarian.BookManagerImpl"%>
<%@page import="jlibrarian.interfaces.BookManager"%>
<%@page import="jlibrarian.entities.Customer"%>
<%@page import="java.util.Collection"%>
<%@page import="jlibrarian.interfaces.CustomerManager"%>
<%@page import="jlibrarian.DbManager"%>
<%@page import="jlibrarian.CustomerManagerImpl"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    BookManager bm = new BookManagerImpl(DbManager.getDataSource());
    Collection<Book> books = bm.getAllBooks();
    boolean nullBooks = (books == null);
%>

<!DOCTYPE html>
<html lang="cs">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/shared/style.css" />
        <title>Seznam knih</title>
    </head>
    <body>
        <h1>jLibrarian</h1>
        <div id="main">
            <div id="menu">
                <div class="group">
                    <h3>Zákazníci</h3>
                    <ul>
                        <li><a href="customer-create.jsp">Nový zákazník</a></li>
                        <li><a href="customer-list.jsp">Zobrazit zákazníky</a></li>
                    </ul>
                </div>
                <div class="group">
                    <h3>Knihy</h3>
                    <ul>
                        <li><a href="book-create.jsp">Nová kniha</a></li>
                        <li><a class="active" href="book-list.jsp">Zobrazit knihy</a></li>
                    </ul>
                </div>
            </div><%--end of menu--%>
            <div id="content">
                <h2>Seznam knih</h2>                
                <%-- start of the messages --%>

                <% if(session != null) out.print(session.getAttribute("messages")); %>
                <% session.setAttribute("messages", "");%>
                <%-- start of the messages --%>


                <p><%= nullBooks ? "V databázi nejsou žádné knihy." : "V databázi je " + books.size() + " knih."%></p>         
                <% if (!nullBooks) {
                        out.println("<table>");
                        out.println("<tr>");
                        out.println("    <th>Titul</th>");
                        out.println("    <th>Autor</th>");
                        out.println("    <th>Počet výtisků</th>");
                        out.println("    <th>Poznámka</th>");
                        out.println("</tr>");

                        for (Book b : books) {
                            out.println("<tr>");
                            out.println("   <td>" + b.getTitle() + "</td>");
                            out.println("   <td>" + b.getAuthors() + "</td>");
                            out.println("   <td>" + b.getQuantity() + "</td>");
                            out.println("   <td>" + b.getNote() + "</td>");
                            out.println("</tr>");
                        }
                        out.println("</table>");
                    }
                %>
            </div><%--end of content--%>        
        </div><%--end of main --%>        
    </body>
</html>
